package com.mou.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mou.dto.MyOrderDTO;
import com.mou.dto.OtherOrderDTO;
import com.mou.dto.TransactionOrderDTO;
import com.mou.entity.Transaction;
import com.mou.vo.TransactionVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

public interface TransactionMapper extends BaseMapper<Transaction> {

    @Select("select count(*) from transaction where buyer_id = #{buyerId} and seller_id = #{sellerId}  and product_id = #{productId} and status = 1")
    Integer orderCount(Transaction transaction);


    @Update("update transaction set status = #{status} where buyer_id = #{buyerId} and seller_id = #{sellerId}  and product_id = #{productId} and status = 1")
    void updateStatus(Transaction transaction);

    @Select("select * from transaction where status = #{status} and transaction_date < #{transactionDate}")
    List<Transaction> getByStatusAndOrderTimeLT(@Param("status") Integer status, @Param("transactionDate") LocalDateTime localDateTime);

    List<Transaction> getListByBuyerId(MyOrderDTO myOrderDTO);

    @Update("update transaction set status = 6 where id = #{id}")
    void cancel(Integer id);
    @Update("update transaction set status = 3 where id = #{id}")
    void accept(Integer id);
    @Update("update transaction set status = 4 where id = #{id}")
    void startDelivery(Integer id);
    @Update("update transaction set status = 5 where id = #{id}")
    void confirmDelivery(Integer id);
    @Select("select id from transaction where buyer_id = #{buyerId} and seller_id=#{sellerId} and product_id =#{productId} and status=1")
    TransactionVO getId(TransactionOrderDTO transactionOrderDTO);
    @Select("select * from transaction where id = #{id} and status = 1")
    Transaction getOrderById(Integer id);
    @Update("update transaction set status = 2 where id = #{orderId}")
    void updatePayStatusById(Integer orderId);


    List<Transaction> getListBySellerId(OtherOrderDTO otherOrderDTO);
}
